export type Method = 'get' | 'GET' |
    'delete' | 'DELETE' |
    'head' | 'HEAD' |
    'options' | 'OPTIONS' |
    'post' | 'POST' |
    'put' | 'PUT' |
    'patch' | 'PATCH'

export interface AxiosRequestConfigs {
    url?: string,
    /**
     * post get put 方法
     */
    method?: string,
    data?: any,
    params?: any,
    headers?: any,
    responseType?: XMLHttpRequestResponseType,
    timeout?: number
    //type XMLHttpRequestResponseType = "" | "arraybuffer" | "blob" | "document" | "json" | "text";
}

export interface AxiosResponse<T = any> {
    data: T,
    status: number,
    statusText: string,
    headers: any,
    config: AxiosRequestConfigs,
    request: any
}

export interface AxiosPromise<T = any> extends Promise<AxiosResponse<T>> {
}


export interface AxiosError extends Error {
    isAxiosError: boolean
    config: AxiosRequestConfigs
    code?: string | null
    request?: any
    response?: AxiosResponse
}

export interface Axios {

    interceptors:{
        request:AxiosInterceptorManeger<AxiosRequestConfigs>,
        response:AxiosInterceptorManeger<AxiosResponse>
    }

    //url不再是必选参数
    /**
     * T 传入什么实体类型,返回什么实体类型
     * @param config
     */
    request<T = any>(config: AxiosRequestConfigs): AxiosResponse<T>

    get<T = any>(url: string, config?: AxiosRequestConfigs): AxiosPromise<T>

    post<T = any>(url: string, data?: any, config?: AxiosRequestConfigs): AxiosPromise<T>

    delete<T = any>(url: string, config?: AxiosRequestConfigs): AxiosPromise<T>

    head<T = any>(url: string, config?: AxiosRequestConfigs): AxiosPromise<T>

    options<T = any>(url: string, config?: AxiosRequestConfigs): AxiosPromise<T>

    put<T = any>(url: string, config?: AxiosRequestConfigs): AxiosPromise<T>

    patch<T = any>(url: string, config?: AxiosRequestConfigs): AxiosPromise<T>
}

export interface AxiosInstance extends Axios {
    //构造函数
    <T = any>(config: AxiosRequestConfigs): AxiosPromise<T>

    /**
     *
     * @param url url的构造器
     * @param config
     */<T = any>(url: string, config?: AxiosRequestConfigs): AxiosPromise<T>
}

export interface AxiosInterceptorManeger<T> {
    /**
     * 必选参数resolve,可选rejected
     * @param resolve
     * @param rejected
     * @return number 提供ID给删除拦截器时使用
     */
    use(resolve:ResolvedFn<T>, rejected?:RejectedFn):number
    eject(id:number):void
}

export interface ResolvedFn<T> {
    (val: T): T | Promise<T>
}

export interface RejectedFn {
    (error: any): any
}